<?php

require(dirname(__FILE__).'/php/PW.php');
require(dirname(__FILE__).'/php/PW.newSlot.php');
require(dirname(__FILE__).'/php/PW.newBooking.php');
require(dirname(__FILE__).'/php/PW.pitchSearch.php');
require(dirname(__FILE__).'/php/PW.newSpecial.php');
require(dirname(__FILE__).'/php/PW.newTeam.php');
require(dirname(__FILE__).'/php/PW.emailTeam.php');
require(dirname(__FILE__).'/php/PW.emailBooking.php');


add_filter('jpeg_quality', function($arg){return 100;});
add_filter( 'wp_editor_set_quality', function($arg){return 100;} );


function register_my_menus()
{
    register_nav_menus(
        array('header-menu' => __('Menu'))
    );
}

add_action('init', 'register_my_menus');

add_action('wp_print_styles', 'my_deregister_styles', 100);

function my_deregister_styles()
{
    wp_deregister_style('wp-admin');
}
/*
function myplugin_update_slug($data, $postarr)
{
    if (!in_array($data['post_status'], array('draft', 'pending', 'auto-draft'))) {
        $data['post_name'] = sanitize_title($data['post_title']);
    }
    return $data;
}

add_filter('wp_insert_post_data', 'myplugin_update_slug', 99, 2);

*/
function get_user_role()
{
    global $current_user;

    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);

    return $user_role;
}

function get_user_id()
{
    global $current_user;
    return $current_user->ID;
}

if (!current_user_can('administrator')):
    show_admin_bar(false);
endif;

add_action( 'wp_login_failed', 'pippin_login_fail' );  // hook failed login
function pippin_login_fail( $username ) {
    $referrer = $_SERVER['HTTP_REFERER'];  // where did the post submission come from?
    // if there's a valid referrer, and it's not the default log-in screen
    if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
        wp_redirect(home_url() . '/login/' );  // let's append some information (login=failed) to the URL for the theme to use
        exit;
    }
}

/**
 * Control the number of search results
 */
function custom_posts_per_page( $query ) {
        set_query_var('posts_per_page', 100000);
}
add_action( 'pre_get_posts', 'custom_posts_per_page' );

ini_set('max_execution_time', 300); //300 seconds = 5 minutes
ini_set('memory_limit ', '128M');